package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;

/**
 * 会员用户角色数据权限配置
 * @author 万宁
 * @version 2.0.0
 * @date 2021-04-02
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_role_auth_config")
public class MemberRoleAuthConfigDO implements Serializable {
    private static final long serialVersionUID = 7510715436189494380L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="member_role_auth_config_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_role_auth_config_seq", name="member_role_auth_config_seq",allocationSize = 1)
    private Long id;

    /**
     * 会员id
     */
    @Column
    private Long memberId;

    /**
     * 一对一单向关联菜单
     */
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "menu_id", referencedColumnName = "id", foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    private MenuDO menu;

    /**
     * 是否具有数据权限
     */
    @Column
    private Integer hasDataAuth;

    /**
     * 多对多单向关联会员组织机构
     */
    @JsonManagedReference
    @ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinTable(name="ms_mc_member_role_auth_config_organization_relation", joinColumns={ @JoinColumn(name="member_role_auth_config_id", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn(name="member_organization_id", referencedColumnName="id")})
    private Set<MemberOrganizationDO> orgs;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public MenuDO getMenu() {
        return menu;
    }

    public void setMenu(MenuDO menu) {
        this.menu = menu;
    }

    public Integer getHasDataAuth() {
        return hasDataAuth;
    }

    public void setHasDataAuth(Integer hasDataAuth) {
        this.hasDataAuth = hasDataAuth;
    }

    public Set<MemberOrganizationDO> getOrgs() {
        return orgs;
    }

    public void setOrgs(Set<MemberOrganizationDO> orgs) {
        this.orgs = orgs;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MemberRoleAuthConfigDO that = (MemberRoleAuthConfigDO) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
